package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbGoodsDescMapper;
import com.dongdongshop.mapper.TbGoodsMapper;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbGoodsDesc;
import com.dongdongshop.pojo.TbGoodsExample;
import com.dongdongshop.service.TbGoogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@com.alibaba.dubbo.config.annotation.Service
@Service
public class TbGoogsServiceImpl implements TbGoogsService {

    @Autowired
    private TbGoodsMapper tbGoodsMapper;

    @Autowired
    private TbGoodsDescMapper tbGoodsDescMapper;

    @Override
    public Boolean insertinto(TbGoods tbGoods, TbGoodsDesc tbGoodsDesc) {

        tbGoodsMapper.insertSelective(tbGoods);

        tbGoodsDesc.setGoodsId(tbGoods.getId());

        tbGoodsDescMapper.insertSelective(tbGoodsDesc);

        return true;
    }

    @Override
    public TbGoods selectByid(Long goodsId) {
        TbGoods tbGoods = tbGoodsMapper.selectByPrimaryKey(goodsId);
        return tbGoods;
    }

    @Override
    public List<TbGoods> selectByName(TbGoods tbGoods) {
        TbGoodsExample tbGoodsExample = new TbGoodsExample();
        /*if(tbGoods.getGoodsName() != null || !tbGoods.getGoodsName().equals("")){
            TbGoodsExample.Criteria criteria = tbGoodsExample.createCriteria();
            criteria.andGoodsNameEqualTo(tbGoods.getGoodsName());
        }*/
        List<TbGoods> tbGoods1 = tbGoodsMapper.selectByExample(tbGoodsExample);
        return tbGoods1;
    }

    @Override
    public void updateGoods(Long[] ids, String auditStatus) {
        tbGoodsMapper.updateGoods(ids,auditStatus);

    }
}
